//add  by  xujun   2017-07-29
var pathName = window.document.location.pathname;  
//获取带"/"的项目名，如：/proj  
var ctx = pathName.substring(0, pathName.substr(1).indexOf('/')+1); 
$(function(){
	jQuery.ajax({
			url:ctx+"/role/getRoleType",
			type: "POST",
			async: "false",
			timeout: 30000,
			success: function(ret){
				if(null==ret){
					parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
					add_close();
				}
				var htrm="";
				for (var k = 0, length = ret.length; k < length; k++) {
					htrm=htrm+"<option value="+ret[k].ddvCode+">"+ret[k].value+"</option>"
					}
				$("#type").html(htrm);
			},
			error: function() {
				parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
				//请求父页面关闭
				add_close();
			}
		});	
	})

//新增数据
	function addRole(){
		var toName=$("#toName").val();
		var type=$("#type").val();
		var notes=$("#note").val();
		if(""==toName){
			parent.$.messager.alert('提示',"请输入名称！", 'info');
			return false;
		}
	jQuery.ajax({
		
		url:ctx+"/role/addRoleJson",
		type: "POST",
		async: "false",
		timeout: 30000,
		data: {"toName":toName,"type":type,"notes":notes},
		success: function(ret) {
			if(ret.state==-1){
				parent.$.messager.confirm('询问', '您还未登录或登录超时！请重新登录？', function(b) {
					if (b) {
						parent.window.location.href=ctx+'/login';
					}
				});
			}
			if(ret.state==0){
				parent.$.messager.show({
					showType:'fade',
				    showSpeed:600,
				    width:300,
				    height:126,
				    msg:'添加成功',
				    title:'提示',
				    timeout:1000,
				    style:{
						right:'',
						top:'200px',
						bottom:'',
					}
				    });
				//请求父页面关闭
				add_close();
			}
			if(ret.state==1){
				parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
				//请求父页面关闭
				add_close();
			}
			if(ret.state==2){
				parent.$.messager.alert('错误', "角色名称已存在", 'error');
				//请求父页面关闭
			}
		},
		error: function() {
			parent.$.messager.alert('错误', "数据异常，添加失败", 'error');
			//请求父页面关闭
			add_close();
		}
	});	
}
	